﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UniversityStudentManagemnetSystem.BLL;
using UniversityStudentManagemnetSystem.DAO.DAL;

namespace UniversityStudentManagemnetSystem.UI
{
    public partial class ViewSingleTeacherPersonalInformation : System.Web.UI.Page
    {
        Teacher aTeacher = new Teacher();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PopulatedNotEnableTextBoxes();
            }
        }

        private void PopulatedNotEnableTextBoxes()
        {
            nameLabel.Visible = false;
            designationLabel.Visible = false;
            departmentLabel.Visible = false;
            emailLabel.Visible = false;
            contactNoLabel.Visible = false;
            addressLabel.Visible = false;
            nameTextBox.Visible = false;
            designationTextBox.Visible = false;
            departmentTextBox.Visible = false;
            emailTextBox.Visible = false;
            conyactNoTextBox.Visible = false;
            addressTextBox.Visible = false;
        }

        protected void searchButton_Click(object sender, EventArgs e)
        {
            try
            {

                string nameOrEmail = nameOrEmailTextBox.Text;
                TeacherManager manager = new TeacherManager();
                aTeacher = manager.GetTeacherForNameOrEmail(nameOrEmail);
                VisibleTextBoxesAndLabels();
                nameTextBox.Text = aTeacher.TeacherName;
                designationTextBox.Text = aTeacher.Designation.DesignationName;
                departmentTextBox.Text = aTeacher.Department.Name;
                emailTextBox.Text = aTeacher.Email;
                conyactNoTextBox.Text = aTeacher.ContactNumber;
                addressTextBox.Text = aTeacher.Address;
            }
                catch(FormatException exception)
                {
                    messageLabel.ForeColor = Color.Red;
                    messageLabel.Text = exception.Message;

                }
            catch (Exception exception)
            {

                messageLabel.ForeColor = Color.Red;
                messageLabel.Text = exception.Message;
            }
        }

        private void VisibleTextBoxesAndLabels()
        {
            nameLabel.Visible = true;
            designationLabel.Visible = true;
            departmentLabel.Visible = true;
            emailLabel.Visible = true;
            contactNoLabel.Visible = true;
            addressLabel.Visible = true;
            nameTextBox.Visible = true;
            designationTextBox.Visible = true;
            departmentTextBox.Visible = true;
            emailTextBox.Visible = true;
            conyactNoTextBox.Visible = true;
            addressTextBox.Visible = true;
        }
    }
}